<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="iOS 多环境配置 Build Configuration"><meta name="keywords" content="iOS"><meta name="author" content="kyren"><meta name="copyright" content="kyren"><title>iOS 多环境配置 Build Configuration | Kyren's Blog</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.9.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.9.0"><meta name="format-detection" content="telephone=no"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://hm.baidu.com"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cf87fcdbd9ab7cf93d894f7c219ae78f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();</script><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script src="https://v1.hitokoto.cn/?encode=js&amp;charset=utf-8&amp;select=.footer_custom_text" defer></script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  hexoVersion: '6.2.0'
} </script><meta name="generator" content="Hexo 6.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar" data-display="true"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%8A%9F%E8%83%BD%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%8D%E5%90%8CBundleID"><span class="toc-number">1.</span> <span class="toc-text">创建一个功能，设置不同BundleID</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%88%9B%E5%BB%BABuild-Configurations"><span class="toc-number">2.</span> <span class="toc-text">一、创建Build Configurations</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%88%9B%E5%BB%BA-User-Defined-Setting"><span class="toc-number">3.</span> <span class="toc-text">二、创建 User-Defined Setting</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E4%BF%AE%E6%94%B9Info-plist%E6%96%87%E4%BB%B6"><span class="toc-number">4.</span> <span class="toc-text">三、修改Info.plist文件</span></a></li></ol></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://avatars.githubusercontent.com/u/5827823?v=4"></div><div class="author-info__name text-center">kyren</div><div class="author-info__description text-center">huluo的技术博客</div><div class="follow-button"><a target="_blank" rel="noopener" href="https://github.com/huluo666">Follow Me</a></div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">239</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">41</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">29</span></a></div><hr><div class="author-info-links"><div class="author-info-links__title text-center">Links</div><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:9090/">Jira</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:8090/">Confluence</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://bloc.leniugame.com/">Leniu</a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">Kyren's Blog</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus">   <a class="site-page" href="/">主页</a><a class="site-page" href="/essay">随笔</a><a class="site-page" href="/archives">归档</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a><a class="site-page" href="/about">关于</a></span><span class="pull-right"><a class="site-page social-icon search"><i class="fa fa-search"></i><span> 搜索</span></a></span></div><div id="post-info"><div id="post-title">iOS 多环境配置 Build Configuration</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2016-03-31</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/iOS/">iOS</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><p>对于有些企业来说，应用在发布到 App Store 之前, 会把应用通过Ad Hoc 形式进行公测。目的是用来模拟真实用户的操作行为和流程,以此来找到一些更不容易发现的 Bug。</p>
<p>产品，测试，都需要自己打包，而且需要打不同环境的多个包，打包需要对配置进行修改，产品还要求公测包标题和图标需要带有Beta字样，这样改了改去非常麻烦而且非常耗费时间。</p>
<p>打包主要分为Debug, Beta, AppStore 这样的版本</p>
<p>其实XCode提供了一个非常容易使用的机制解决这些问题: Build Configuration</p>
<p>最终的目标是:<br>1、每个环境有一个单独的配置文件。例如我们可以改变测试服务器和生产服务器的URL。<br>2、有不同的包标识符,为每个环境设置包名称和应用程序图标。 这样做确保您可以直接识别哪个版本是安装在一个设备上。也许更重要的是,它还可以让我们在设备上有多个版本,因为每个环境都有自己的包标识符。<br>3、有一个预处理器宏能够区分不同环境。<br>​<br>当您创建一个新项目,Xcode已经提供了两种配置的: release 和 Debug</p>
<h3 id="创建一个功能，设置不同BundleID"><a href="#创建一个功能，设置不同BundleID" class="headerlink" title="创建一个功能，设置不同BundleID"></a>创建一个功能，设置不同BundleID</h3><p>不同版本要有不同的Bundle ID,比如</p>
<ol>
<li>com.mycompany.myapp.debug – Debug版本</li>
<li>com.mycompany.myapp.inhouse – (Ad Hoc, Beta) 版本</li>
<li>com.mycompany.myapp —App Store(Production) 版本</li>
</ol>
<p>多环境配置步骤</p>
<h3 id="一、创建Build-Configurations"><a href="#一、创建Build-Configurations" class="headerlink" title="一、创建Build Configurations"></a>一、创建Build Configurations</h3><p>默认Xcode会提供2个Build配置项(Build Configuration):Debug和Release。一般来说这样两种情况就足够了，但是在有些时候我们需要添加一个或多个新的配置项，添加一个新的配置项的步骤如下：</p>
<p>1）、方式：选中PROJECT的名称，然后选中Info，点击Configurations下面的<code>+</code>选择<code>Duplicate &quot;Debug&quot;Configuration</code> 生成一个新Configuration,双击重命名configuration ，修改如下图：<br><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/03/31/FgWRnjX0WKEYIjRoBkmlheyMzfxN479.png"></p>
<h3 id="二、创建-User-Defined-Setting"><a href="#二、创建-User-Defined-Setting" class="headerlink" title="二、创建 User-Defined Setting"></a>二、创建 User-Defined Setting</h3><p>在Xcode中使用User-Defined Setting可以定义一些Xcode编译使用的宏配置，以便我们为不同的配置能够分配不同的包ID，图标名称或AppID。</p>
<p>1、开启User-Defined Setting，如下图：<br><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/03/31/Frvrx6jiUF9AzXTw3QHWlrRHppQc479.png"></p>
<p>2、在这个例子中，我创建了2个不同的用户自定义设置; <code>APP_BUNDLE_ID (APP Bundle ID)</code>和<code>APP_DISPLAY_NAME(APP的名称)</code>。</p>
<p>添加User-Defined Setting后，编辑里面每个设置构建配置值<br>效果如下图：</p>
<p><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/03/31/FlOrq2HK2R75jqp4mEJisoQvPwDh479.png"></p>
<p>3.App Icon 设置<br>在 Media Assets 中 (在项目中的默认名字应该是 Images.xcassets), 点击菜单 “Editor” -&gt; “New App Icon”, 建立两个新的 App Icon, 分别对应 Debug 和 Staging 版本. 然后把之前准备好的图标分别拖进去. 如图:<br><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/03/31/FufHtzkg6spZBKdUwIUBkprxsY2P479.png"></p>
<p>点击AppIcon添加管理AppICon<br><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/04/01/FkLqdrqhWcE7cGr16Ryv8Dkl7Wul758.png" alt="添加图标1"></p>
<p><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/04/01/Fv9EinlyuD1uZIt_FUpky3YPpg3P758.png"></p>
<h3 id="三、修改Info-plist文件"><a href="#三、修改Info-plist文件" class="headerlink" title="三、修改Info.plist文件"></a>三、修改Info.plist文件</h3><p>所有在上一步中定义的User-Defined Setting将在项目的info.plist中使用。<br>修改您的info.plist，通过插入用户自定义设置中定义的值。</p>
<p>Bundle identifiter(捆绑标识符)：<code>$(APP_BUNDLE_ID)</code><br>Bundle display name(包显示名称)：演示应用<code>$(APP_DISPLAY_NAME)</code></p>
<p><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/03/31/FiV6Qzk3xYlQPXEWBu5cSSFKz_TV513.png"></p>
<p>设置完毕后，可进行Run测试，Debug,Beta，Release 编译后进入手机桌面，该工程将会有不同图标，名称的App。<br><img src="http://7xr7vj.com1.z0.glb.clouddn.com/2016/04/01/FhBRLfhncgDOQS6a1QgicO2SI9Qr445.jpeg"></p>
<p><code>设置多个Scheme</code><br>当然也可以设置多个Scheme进行管理<code>shift+cmmand+&lt;</code>,勾选shared以便git同步<br><a target="_blank" rel="noopener" href="http://7xr7vj.com1.z0.glb.clouddn.com/2016/04/01/FhBRLfhncgDOQS6a1QgicO2SI9Qr445.jpeg"></a></p>
<p><strong>测试相关信息</strong></p>
<p>1：获取<code>bundle Id</code>信息：[[NSBundle mainBundle] bundleIdentifier]；</p>
<p>2：获取版本号：[[[NSBundle mainBundle]infoDictionary] objectForKey:@”CFBundleVersion”];</p>
<p>3: 获取App显示名：[[[NSBundle mainBundle]infoDictionary] objectForKey:@”CFBundleDisplayName”];</p>
<p>参考网址：<br><a target="_blank" rel="noopener" href="http://appfoundry.be/blog/2014/07/04/Xcode-Env-Configuration/">http://appfoundry.be/blog/2014/07/04/Xcode-Env-Configuration/</a><br><a target="_blank" rel="noopener" href="http://ravelantunes.com/blog/xcode-build-process/">http://ravelantunes.com/blog/xcode-build-process/</a><br><a target="_blank" rel="noopener" href="http://www.teratotech.com/blog/xcode-7-steps-to-easily-switch-between-multiple-environments/">http://www.teratotech.com/blog/xcode-7-steps-to-easily-switch-between-multiple-environments/</a></p>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">kyren</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huluo666.gitee.io/2016/03/31/iOS多环境配置/">http://huluo666.gitee.io/2016/03/31/iOS多环境配置/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huluo666.gitee.io">Kyren's Blog</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/iOS/">iOS</a></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2016/04/06/Mac%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BANuclide%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/"><i class="fa fa-chevron-left">  </i><span>学习React Native:Mac环境搭建Nuclide安装与配置</span></a></div><div class="next-post pull-right"><a href="/2016/03/30/iOS%20%E9%AB%98%E6%95%88%E7%8E%87%E7%BC%96%E7%A8%8B%E5%B7%A5%E5%85%B7%E7%AF%87/"><span>iOS 高效率编程工具篇</span><i class="fa fa-chevron-right"></i></a></div></nav></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2022 By kyren</div><div class="framework-info"><span>驱动 - </span><a target="_blank" rel="noopener" href="http://hexo.io"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a target="_blank" rel="noopener" href="https://github.com/Molunerfinn/hexo-theme-melody"><span>Melody</span></a></div><div class="footer_custom_text">hitokoto</div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv"><i class="fa fa-file"></i><span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/lib/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.9.0"></script><script src="/js/fancybox.js?version=1.9.0"></script><script src="/js/sidebar.js?version=1.9.0"></script><script src="/js/copy.js?version=1.9.0"></script><script src="/js/fireworks.js?version=1.9.0"></script><script src="/js/transition.js?version=1.9.0"></script><script src="/js/scroll.js?version=1.9.0"></script><script src="/js/head.js?version=1.9.0"></script><script src="/js/search/local-search.js"></script><script>if(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
  $('#top-container').addClass('is-mobile')
}</script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html>